﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Web;
using System.Net;
using System.Threading.Tasks;
namespace LoginWebUsingWebBrowser
{
    public partial class frmCrawler : Form
    {
        public frmCrawler()
        {
            InitializeComponent();

        }

        private string Path;
        public List<string> users = new List<string>();
        Regex rex = new Regex(@"<cite>.*?>(\w*?)</a></cite>\s*<p><em>\w+\s(\d)</em></p>");
        private void btnGo_Click(object sender, EventArgs e)
        {
            Path = txtPath.Text;
            Task.Factory.StartNew((Action)(() =>
                                           {

                                               DirectoryInfo di = new DirectoryInfo(Path);
                                               var files = di.GetFiles();
                                               foreach (var fileInfo in files)
                                               {
                                                   var fs = fileInfo.OpenRead();
                                                   StreamReader sr = new StreamReader(fs);
                                                   string data = sr.ReadToEnd();
                                                   var ms = rex.Matches(data);
                                                   for (int i = 0; i < ms.Count; i++)
                                                   {
                                                       int l = int.Parse(ms[i].Groups[2].ToString());
                                                       if (l > 1)
                                                       {
                                                           string userName = ms[i].Groups[1].ToString();

                                                           if (!users.Contains(userName))
                                                           {
                                                               users.Add(userName);
                                                           }
                                                       }
                                                   }
                                               }
                                               MessageBox.Show(users.Count.ToString());
                                               File.WriteAllLines(Path + "\\users.txt", users);
                                               MessageBox.Show("done");
                                           }));
        }
    }
}
